<template>
  <div class="page">
    <div class="head">
      <h1>全服城堡战斗记录</h1>
    </div>
    <div class="records">
      <router-link tag="div" class="panel" v-for="(item,index) in records" :key="index" :to="`/battle?id=${item.id}`">
        <p>{{ item.attackTime | formatTime }}</p>
        <div class="battle">
          <div class="attack">
            <img :src="item.attackerImg" :style="{background: '#eafee1'}">
            <p>[攻]{{ item.attacker }}</p>
          </div>
          <div class="result">
            <img :src="`/static/result-${item.reslut}.svg`">
            <p>攻击{{item.reslut == 1 ? '成功' : '失败'}}</p>
          </div>
          <div class="defense">
            <img :src="item.castleImg" :style="{background: '#eafee1'}">
            <p>[防]{{ item.castleName }}</p>
          </div>
        </div>
      </router-link>
      <infinite-loading @infinite="initData" ref="infiniteLoading2">
        <span slot="no-more"></span>
        <div slot="no-results">
          <br>
          <empty></empty>
        </div>
        <spinner slot="spinner" type="lines"></spinner>
      </infinite-loading>
    </div>
  </div>
</template>

<script>
  import {
    Spinner
  } from 'vux'
  import empty from './common/empty.vue'
  import InfiniteLoading from 'vue-infinite-loading';
  export default {
    components: {
      empty,
      InfiniteLoading,
      Spinner
    },
    data() {
      return {
        records: [],
        current: 1,
        type: ['战败', '胜利', '大获全胜！']
      }
    },
    mounted() {
      this.$nextTick(function() {
        this.isAll = this.$route.query.t
      });
    },
    methods: {
      initData($state) {
        this.$http
          .post(`/gameCastle/attackRecordList`, {
            current: this.current,
          })
          .then(res => {
            if (res.code == 200) {
              if (res.result.total > 0) {
                this.records = this.records.concat(res.result.records);
                $state.loaded();
                if (res.result.current < res.result.pages) {
                  this.current += 1;
                } else {
                  $state.complete();
                }
              } else {
                $state.complete();
              }
            } else {}
          })
          .catch(function(error) {});
      }
    }
  }
</script>

<style lang="scss" scoped>
  .panel {
    padding: 8px;
    p {
      font-size: 12px;
      color: $grey;
    }
  }
  .battle {
    display: flex;
    align-items: center;
    font-size: 12px;
    div {
      width: 33.33%;
      white-space: nowrap;
      overflow: hidden;
      text-align: center;
      p {
        text-overflow: ellipsis;
        overflow: hidden;
      }
    }
    img {
      width: 60px;
      height: 60px;
    }
    .result {
      img {
        width: 40px;
        height: 40px;
      }
    }
    .attack p {
      color: #d0021b;
    }
    .defense p {
      color: #4a90e2;
    }
  }
  .red {
    color: $red;
  }
  .green {
    color: $green;
  }
</style>
